package com.study.demo_redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: HelloController
 * @Description:
 * @author: WS
 * @date 2020/12/18
 * @Version: 1.0
 **/
@RestController
public class HelloController {
    @Value("${server.port}")
    Integer port;
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @GetMapping("/set")
    public void set(){
        ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
        stringStringValueOperations.set("name","hello redis");
    }
    @GetMapping("/get")
    public void get(){
        ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
        String name = stringStringValueOperations.get("name")+"    port:"+port;
        System.out.println(name);
    }
}
